#ifndef PICCOLO_VK_RENDER_PASS_H
#define PICCOLO_VK_RENDER_PASS_H

#include "PiccoloVKCommon.h"

namespace Piccolo
{
    class PiccoloVKDevice;
    class PiccoloVKFrameBuffer;

    struct Attachment
    {
        VkFormat format = VK_FORMAT_UNDEFINED;
        VkAttachmentLoadOp loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
        VkAttachmentStoreOp storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
        VkAttachmentLoadOp stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
        VkAttachmentStoreOp stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
        VkImageLayout initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
        VkImageLayout finalLayout = VK_IMAGE_LAYOUT_UNDEFINED;
        VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT;
        VkImageUsageFlags usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
    };

    struct RenderSubPass
    {
        std::vector<uint32_t> inputAttachments;
        std::vector<uint32_t> colorAttachments;
        std::vector<uint32_t> depthStencilAttachments;
        VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
    };

    class PiccoloVKRenderPass
    {
    public:
        PiccoloVKRenderPass(PiccoloVKDevice* device, const std::vector<Attachment>& attachments = {}, const std::vector<RenderSubPass>& renderSubPasses = {});
        ~PiccoloVKRenderPass();

        VkRenderPass GetRenderPass() const { return mRenderPass; }

        void BeginRenderPass(VkCommandBuffer commandBuffer, PiccoloVKFrameBuffer* frameBuffer, const std::vector<VkClearValue>& clearValues) const;
        void EndRenderPass(VkCommandBuffer commandBuffer) const;

        const std::vector<Attachment>& GetAttachments() const { return mAttachments; }
        uint32_t GetAttachmentSize() const { return mAttachments.size(); }
        const std::vector<RenderSubPass>& GetSubPasses() const { return mRenderSubPasses; }

    private:
        VkRenderPass mRenderPass = VK_NULL_HANDLE;
        PiccoloVKDevice* mDevice;

        std::vector<Attachment> mAttachments;
        std::vector<RenderSubPass> mRenderSubPasses;
    };
}

#endif